package org.grew.openEntity.po.system;

import org.springframework.data.domain.Page;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: Administrator
 * @Date: 2019/1/10 08:48
 * @Description:
 */
public class PageObj {

    private static final int PAGE_NUM = 5;

    private String beforePageUrl;
    private PageNum[] pageNums;
    private String afterPageUrl;

    public PageObj() {

    }

    public PageObj(int pageIndex, int totalPage,String url) {
        pageIndex = pageIndex<0?0:pageIndex;
        beforePageUrl = "#";
        afterPageUrl = "#";
        if(pageIndex-1>=0){
            beforePageUrl = url+(pageIndex-1);
        }
        if(pageIndex+1<totalPage){
            afterPageUrl = url+(pageIndex+1);
        }
        /**判断页面是否小于页码中间数**/
        if (pageIndex <= (PAGE_NUM / 2 + 1)) {
            /**判断页面是否大于页码数**/
            if (totalPage >= PAGE_NUM) {
                pageNums = new PageNum[PAGE_NUM];
            } else {
                pageNums = new PageNum[totalPage];
            }
            for (int i = 0; i < pageNums.length; i++) {
                pageNums[i] = new PageNum(i, url+i);
            }
        } else {
            int p = totalPage - pageIndex;
            /**判断当前是不是最后一页**/
            if (p == 0) {
                pageNums = new PageNum[PAGE_NUM];
            } else if (p >= PAGE_NUM / 2) {
                pageNums = new PageNum[PAGE_NUM];
            } else {
                pageNums = new PageNum[PAGE_NUM - p];
            }
            for (int i = pageIndex + p; i > pageIndex + p - PAGE_NUM; i--) {
                pageNums[i] = new PageNum(i,url+i);
            }
        }


    }

    public String getBeforePageUrl() {
        return beforePageUrl;
    }

    public void setBeforePageUrl(String beforePageUrl) {
        this.beforePageUrl = beforePageUrl;
    }

    public PageNum[] getPageNums() {
        return pageNums;
    }

    public void setPageNums(PageNum[] pageNums) {
        this.pageNums = pageNums;
    }

    public String getAfterPageUrl() {
        return afterPageUrl;
    }

    public void setAfterPageUrl(String afterPageUrl) {
        this.afterPageUrl = afterPageUrl;
    }
}
